// Package _3_II_0_n_1中缺失的数字 main
// @Title _3_II_0_n_1中缺失的数字
// @Description
// @Author  == 琳琳也叫王木木 ==  2022-01-16 18:38
// @Create  2022-01-16 18:38
package main

import "fmt"

func main() {
	fmt.Println(missingNumber([]int{0}))
}

//
//  missingNumber
//  @Description: 使用二分查找法
//  @param nums：
//  @return int：
//
func missingNumber(nums []int) int {
	if len(nums) == 0 {
		return -1
	}
	l, r := 0, len(nums)-1
	for l <= r {
		m := l + (r-l)>>2
		if nums[m] == m {
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return l
}

func missingNumber2(nums []int) int {
	if len(nums) == 0 {
		return -1
	}
	l, r := 0, len(nums)-1
	for l <= r {
		m := l + (r-l)>>2
		if nums[m] == m {
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return l
}
